#ifndef __BUOLA_CV_PYRA_H__
#define __BUOLA_CV_PYRA_H__

#include <pyra/tpimage.h>
#include <buola/image/format.h>

namespace buola { namespace cvi {

template<typename tImage,typename tStorage>
class CPyraWrapper
{
public:
    CPyraWrapper(tImage &pData)
        :   mPyraImage(sizeof(typename tImage::TValue)*tImage::cChannels*pData.Width()/sizeof(tStorage),pData.Height(),(tStorage*)
                  pData.RawData())
    {
    }    

    CPyraWrapper(const img::CView<typename tImage::TFormat> &pData)
        :   mPyraImage(sizeof(typename tImage::TValue)*tImage::cChannels*pData.Width()/sizeof(tStorage),pData.Height(),(tStorage*)
                  pData.RawData())
    {
    }    

    CPyraWrapper(const CPyraWrapper &pRH)
        :   mPyraImage(pRH.mPyraImage)
    {
    }
    
    operator Image<tStorage>&()
    {
        return mPyraImage;
    }
    
    Image<tStorage> mPyraImage;
};

inline CPyraWrapper<img::CImage_gray8,unsigned char> pyra_wrap(
                              img::CImage_gray8 &pData)
{
    return CPyraWrapper<img::CImage_gray8,unsigned char>(pData);
}

inline CPyraWrapper<img::CImage_gray32f,float> pyra_wrap(
                              img::CImage_gray32f &pData)
{
    return CPyraWrapper<img::CImage_gray32f,float>(pData);
}

inline CPyraWrapper<img::CImage_rgb8,unsigned char> pyra_wrap(
                              img::CImage_rgb8 &pData)
{
    return CPyraWrapper<img::CImage_rgb8,unsigned char>(pData);
}

inline CPyraWrapper<img::CImage_gray8,unsigned char> pyra_wrap(
                              const img::CView_gray8 &pData)
{
    return CPyraWrapper<img::CImage_gray8,unsigned char>(pData);
}

inline CPyraWrapper<img::CImage_gray32f,float> pyra_wrap(
                              const img::CView_gray32f &pData)
{
    return CPyraWrapper<img::CImage_gray32f,float>(pData);
}

inline CPyraWrapper<img::CImage_rgb8,unsigned char> pyra_wrap(
                              const img::CView_rgb8 &pData)
{
    return CPyraWrapper<img::CImage_rgb8,unsigned char>(pData);
}

/*namespace cvi*/ } /*namespace buola*/ }

#endif
